package ai.yue.open.service.cd.forest.auth;

import com.alibaba.fastjson2.JSONObject;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.JSONBody;
import com.dtflys.forest.annotation.Put;
import com.dtflys.forest.annotation.Var;
import com.dtflys.forest.http.ForestResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

/**
 * Rancher Api调用
 *
 * @author yl-yue
 * @since  2023/2/7
 */
public interface AuthRancherApiForest {

    /**
     * 获取工作负载信息
     */
    @Get(url = "{workloadApiUrl}", headers = {HttpHeaders.AUTHORIZATION + ":" + "${bearerToken}"})
    ForestResponse<JSONObject> getWorkload(@Var("workloadApiUrl") String workloadApiUrl, @Var("bearerToken") String bearerToken);

    /**
     * 重新部署工作负载
     */
    @Put(
            url = "{workloadApiUrl}",
            headers = {
                    HttpHeaders.AUTHORIZATION + ":" + "${bearerToken}",
                    HttpHeaders.CONTENT_TYPE + ":" + MediaType.APPLICATION_JSON_VALUE
            }
    )
    ForestResponse<String> actRedeploy(@Var("workloadApiUrl") String workloadApiUrl, @Var("bearerToken") String bearerToken, @JSONBody JSONObject body);

}
